<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
  <title>Ubiquity Web Search Commands for Japanese, nora - kakaku</title>
</head>
<body>
<p>This xhtml source contains commands for searching the Web.  Its
corresponding feed is <a href="ubiquity-commands-ja-nora-kakaku.html">here</a>.</p>

<div id="kakaku" style="display: none;">
<b>${query}</b>でkakaku.comを検索:
<br/>
{for item in items}
  <div style="clear:both;font-size:90%;border:1px solid #777777; -moz-border-radius:4px;background:#333333;margin:1px 0px 0px 0px;padding:0px;">
    <div style="border:1px solid #777777; -moz-border-radius:4px;background:#666666;margin:0px;padding:0px;">
        <a href="${item.url}" accesskey="${item.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${item.key}</span><b>${item.title}</b></a>
    </div>
    <div>
        {if item.imgsrc}
            <img
                src="${item.imgsrc}"
                style="float: left;margin: 1px 2px 1px 1px; width: 50px;"
                alt="${item.imgalt}"
            />
        {/if}
        <div style="margin-left: 20px; font-size: 85%;">
          ${item.description}
        </div>
        <div style="clear:left;"> </div>
    </div>
  </div>
{forelse}
  <b>該当項目が見つかりませんでした</b>
{/for}
<div style="font-size:30%;"> <br/></div>
{for category in categories}
    <div style="clear:both;font-size:80%;border:1px solid #666666; -moz-border-radius:3px;background:#444444;margin:0px;padding:0px;">
        <A href="${category.url}" accesskey="${category.key}"><span style="font-size:xx-small; border-width:1px; border-style:solid;-moz-border-radius:2px; padding:0px 2px 0px 2px; vertical-align:center; margin-left:1px; max-width:20px; max-height:10px; overflow:visible;float:none;background: #dddddd;color:#333333;">${category.key}</span></A> ${category.html}
    </div>
{/for}
<div style="font-size:70%;clear:both;margin:7px 0px 0px 0px;">※[Ctrl]+[Alt]+[番号] でジャンプ</div>
</div>

<script class="commands"><![CDATA[
CmdUtils.CreateCommand({
    name: "kakaku",
    description: "kakaku.com を検索します",
    takes: {search: noun_arb_text},
    icon: "http://kakaku.com/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {

        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "kakaku.com を検索";
            previewBlock.innerHTML = previewStr;
            return;
        }

        var previewTemplate = "<b>${query}</b> を kakaku.com から検索します...";
        var previewData = {query: searchText};
        previewBlock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
        
        var searchUrl = "http://kakaku.com/search_results/?query=" + escape(Utils.convertFromUnicode("Shift-JIS", searchText ) );
        
        CmdUtils.previewAjax(previewBlock, {
          type: "GET",
          url: searchUrl,
          dataType: "html",
          
          
          beforeSend: function(xhr){
            xhr.overrideMimeType("text/html;charset=Shift_JIS");
          },
          
            
          error: function() {
            previewBlock.innerHTML = "Error searching kakaku.com.";
          },
          
          success: function(responseData) {
            
            responseData = jQuery(responseData);
            
            var resultBoxes = responseData.find(".resultBox01");
            
            var items = [];
            var count = resultBoxes.length;
            
            count = ( count>=5 ) ? 5 : count;
            
            for (var i = 0; i < count; i++){
                
                var resultBox = jQuery(resultBoxes[i]);
                
                resultBox.find(".details BR").replaceWith(" ");
                
                var item = {
                    imgsrc : resultBox.find(".leftBox img").attr("src"),
                    imgalt : resultBox.find(".leftBox img").attr("alt"),
                    url : resultBox.find(".leftBox a").attr("href"),
                    title : resultBox.find(".title").text(),
                    description : "<b>" + 
                                    resultBox.find(".itemTitleBar + p").text() + "</b>" + 
                                    resultBox.find(".details + div").text() + "<br/>" + 
                                    resultBox.find(".details").text(),
                    key: i+1
                };
                
                items.push(item);
                
            }
            
            var categories = [];
            var ck = 6;
            var seekBoxpes = responseData.find("#More1_pnlMore .seekBody");
            
            seekBoxpes.find(".seekBoxp").each(function(){
                
                var seekBoxp = jQuery(this);
                
                var category = {
                    html : seekBoxp.html(),
                    url : seekBoxp.find("a").attr("href"),
                    key : ck++
                }
                
                categories.push(category);
            });
            
            var previewData = {
                query: searchText,
                items: items,
                categories : categories
            };
            
            previewBlock.innerHTML = CmdUtils.renderTemplate(
              jQuery("#kakaku", feed.dom).html(),
              previewData);
          }
        });

    },

    execute: function( directObject ) {
        var queryText = Utils.convertFromUnicode("Shift-JIS", directObject.text);
        queryText = escape(queryText);
        Utils.openUrlInBrowser( "http://kakaku.com/search_results/" + queryText );
    }
});



]]></script>
</body>
</html>
